package com.zjjk.transfer.source.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.zjjk.transfer.source.entity.SourceSurplus;
import com.zjjk.transfer.source.mapper.SourceSurplusMapper;
import com.zjjk.transfer.source.service.SourceSurplusService;
import com.zjjk.transfer.source.param.SourceSurplusPageParam;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.geekidea.springbootplus.framework.common.service.impl.BaseServiceImpl;
import io.geekidea.springbootplus.framework.core.pagination.Paging;
import io.geekidea.springbootplus.framework.core.pagination.PageInfo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.transaction.annotation.Transactional;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * 结余记录表 服务实现类
 *
 * @author xuziyang
 * @since 2021-03-26
 */
@Slf4j
@Service
@DS("source")
public class SourceSurplusServiceImpl extends BaseServiceImpl<SourceSurplusMapper, SourceSurplus> implements SourceSurplusService {

    @Autowired
    private SourceSurplusMapper sourceSurplusMapper;

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean saveSourceSurplus(SourceSurplus sourceSurplus) throws Exception {
        return super.save(sourceSurplus);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean updateSourceSurplus(SourceSurplus sourceSurplus) throws Exception {
        return super.updateById(sourceSurplus);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean deleteSourceSurplus(Long id) throws Exception {
        return super.removeById(id);
    }

    @Override
    public Paging<SourceSurplus> getSourceSurplusPageList(SourceSurplusPageParam sourceSurplusPageParam) throws Exception {
        Page<SourceSurplus> page = new PageInfo<>(sourceSurplusPageParam, OrderItem.desc(getLambdaColumn(SourceSurplus::getCreateTime)));
        LambdaQueryWrapper<SourceSurplus> wrapper = new LambdaQueryWrapper<>();
        IPage<SourceSurplus> iPage = sourceSurplusMapper.selectPage(page, wrapper);
        return new Paging<SourceSurplus>(iPage);
    }

}
